<template>
  <view class="video_paly">
    <!-- 背景 -->
    <image :src="videoObj.img"></image>
    <!-- 工具栏 S -->
    <view class="video_tool">
      <view :class="['iconfont', muted?'icon-sound-Mute':'icon-sound-filling']" @click="muted = !muted"></view>
      <view class="iconfont icon-share">
        <button open-type="share"></button>
      </view>
    </view>
    <!-- 工具栏 E -->
    <!-- 视频 S -->
    <view class="video_wrap">
      <video :muted="muted" :src="videoObj.video" objectFit="fill"></video>
    </view>
    <!-- 视频 E -->
    <!-- 下载 S -->
    <view class="video_download">
      <view class="download_btn" @click="handleDownload">下载高清</view>
    </view>
    <!-- 下载 E -->
  </view>
</template>
<script>
export default {
  data() {
    return {
      videoObj: {},
      muted: false
    }
  },
  onLoad(){
    this.videoObj =  getApp().globalData.video;
  },
  methods: {
    async handleDownload(){
      await uni.showLoading({
        title: '下载中'
      });
      const {tempFilePath} = (await uni.downloadFile({ url:this.videoObj.video }))[1];
      await uni.saveVideoToPhotosAlbum({filePath: tempFilePath});
      uni.hideLoading();
      await uni.showToast({
        title: '下载成功'
      });
    }
  },
}
</script>
<style lang="scss" scoped>
  .video_paly {
    position: relative;
  image {
    position: absolute;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    // css3 滤镜
    filter: blur(20rpx);
  }

  .video_tool {
    height: 80rpx;
    display: flex;
    justify-content: flex-end;
    .iconfont{
      width: 80rpx;
      height: 80rpx;
      color: #fff;
      font-size: 50rpx;
      border-radius: 40rpx;
      background-color: rgba(0,0,0,.2);
      display: flex;
      justify-content: center;
      align-items: center;
      margin-right: 20rpx;
    }
    .icon-sound-filling {

    }

    .icon-share {
      position: relative;
      button {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
      }
    }
  }

  .video_wrap {
    display: flex;
    justify-content: center;
    video {
      width: 360rpx;
      height: 600rpx;
    }
  }

  .video_download {
    display: flex;
    justify-content: center;
    margin-top: 30rpx;
    .download_btn {
      width: 360rpx;
      height: 80rpx;
      border-radius: 40rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      border: 1rpx solid #fff;
      background-color: rgba(0,0,0,.5);
    }
  }
}
</style>